<template>
    <div class="app-container">
       <el-form :model="queryParams" ref="queryRef" v-show="showSearch" :inline="true" label-width="120px">
          <el-form-item label="用户ID/手机号：" prop="roleName">
             <el-input
                v-model="queryParams.keyword"
                placeholder="请输入"
                clearable
                style="width: 240px"
                @keyup.enter="handleQuery"
             />
          </el-form-item>
          <el-form-item>
             <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
             <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
       </el-form>
       <el-row :gutter="10" class="mb8">
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
       </el-row>
 
       <!-- 表格数据 -->
       <el-table v-loading="loading" :data="roleList">
        <el-table-column label="" prop="roleId" width="100">
              <template #default="scope">
                <span class="idx"  :style="{ backgroundColor: scope.$index < 3 ? 'black' : 'gray' }">
                  {{scope.$index + 1}}
                </span>
              </template>
          </el-table-column>
          <el-table-column label="用户头像" prop="faceURL" :show-overflow-tooltip="true">
            <template #default="scope">
              <span class="avatar" v-if="scope.row.faceURL === ''">
                  {{scope.row.nickname[0]}}
              </span>
              <div v-else>
                <img :src="scope.row.faceURL" alt="light" />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="用户呢称" prop="nickname" :show-overflow-tooltip="true" />
          <el-table-column label="用户ID" prop="userID" />
          <el-table-column label="性别" prop="gender" />
          <el-table-column label="手机号" prop="phoneNumber" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
             <template #default="scope">
                <el-button link type="primary"  @click="handleDelete(scope.row)">解封</el-button>
             </template>
          </el-table-column>
       </el-table>
 
       <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="pageObj.pageNumber"
          v-model:limit="pageObj.showNumber"
          @pagination="getList"
       />      
    </div>
 </template>
 
 <script setup name="blockList">
 import { getBlockList, delBlock } from "@/api/chat/block";
 
 const router = useRouter();
 const { proxy } = getCurrentInstance();
 
 const roleList = ref([]);
 const open = ref(false);
 const loading = ref(true);
 const showSearch = ref(true);
 const total = ref(0);
 const title = ref("");
 const dateRange = ref([]);
 
 /** 数据范围选项*/
 const dataScopeOptions = ref([
   { value: "1", label: "全部数据权限" },
   { value: "2", label: "自定数据权限" },
   { value: "3", label: "本部门数据权限" },
   { value: "4", label: "本部门及以下数据权限" },
   { value: "5", label: "仅本人数据权限" }
 ]);
 
 const data = reactive({
   queryParams: {
    keyword:undefined,
    pageSize: 10,
    current:1
   },
   pageObj:{
     pageNumber: 1,
     showNumber: 10,
   },
 });
 
 const { queryParams, pageObj } = toRefs(data);
 
 /** 查询角色列表 */
 function getList() {
   loading.value = true;
   const params = {
    pagination: data.pageObj,
    ...data.queryParams
   }
   getBlockList(params).then(response => {
     roleList.value = response.data.users;
     total.value = response.data.total;
     loading.value = false;
   });
 }
 
 /** 搜索按钮操作 */
 function handleQuery() {
   queryParams.value.pageNum = 1;
   getList();
 }
 
 /** 重置按钮操作 */
 function resetQuery() {
   dateRange.value = [];
   proxy.resetForm("queryRef");
   handleQuery();
 }
 
 /** 删除按钮操作 */
 function handleDelete(row) {
   const roleIds = row.userID;
   const parmas = {
    userIDs:[roleIds]
   }
   proxy.$modal.confirm('是否确认解封该用户').then(function () {
     return delBlock(parmas);
   }).then(() => {
     getList();
     proxy.$modal.msgSuccess("解封成功");
   }).catch(() => {});
 }

 getList();
 </script>
 